package com.pvdnc.tapkit.chat.chat.server;

import com.pvdnc.nsocket.log.SLog;
import com.pvdnc.nsocket.server.ClientManager;
import com.pvdnc.nsocket.server.ClientProxy;
import com.pvdnc.nsocket.server.handler.SimpleServerHandler;
import com.pvdnc.tapkit.chat.chat.ChatServer;
import com.pvdnc.tapkit.chat.chat.packet.TextMessage;

import io.netty.channel.ChannelHandlerContext;

public class OnTextMessage extends SimpleServerHandler<ChatServer, TextMessage> {
    private static final SLog LOG=new SLog(OnTextMessage.class);
    public OnTextMessage(ChatServer server) {
        super(server,TextMessage.COMMAND);
    }

    @Override
    public void onReceived(ChannelHandlerContext ctx, TextMessage msg) {
        ClientProxy proxy= ClientManager.getInstance().getClient(msg.mToName);
        if(proxy==null){
            LOG.e("client:"+msg.mToName+" does not exist");
            return;
        }
        proxy.send(msg,false);
    }
}
